package com.woniu.job.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.job.entity.Company;
import com.woniu.job.entity.vo.ResultVO;
import com.woniu.job.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author sunnylausong
 *  查看管理企业
 * 2019/12/27
 * 16:09
 */

@RestController("adminCompanyController")
@RequestMapping("/admin/company")
public class CompanyController {
    @Autowired
    ICompanyService companyService;

    /**
     * 获取列表分页
     * @param p page
     * @return
     */
    @GetMapping("/list/{p}")
    public ResultVO<Page<Company>> getList(@PathVariable int p)
    {
        p = p < 1 ? 1 : p;
        // pageSize=10
//        companyService.page(new Page<Company>(p,10)
//                ,new QueryWrapper<Company>().like("name","1").gt);

        Page<Company> list = companyService.page(new Page<>(p, 10));
        // 去掉密码
        list.getRecords().forEach(t -> {
            t.psw(null);
        });
        return new ResultVO<>(list);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/update/{id}/{forbidden}")
    public ResultVO delete(@PathVariable String id, @PathVariable Boolean forbidden)
    {
        String status = null;
        if (forbidden) {
            status = "2";
        } else {
            status = "1";
        }
        companyService.updateById(new Company().id(id).status(status));
        return ResultVO.SUC.message("修改成功！");
    }
}
